<?php
class Lists extends MY_Controller
{
	public function __construct()
	{
		log_message('debug', '=====开始调用Pay->Lists->__construct接口=====');
		parent::__construct();
		$this->loadLanguageFile('application/controllers/Pay/');
		log_message('debug', '=====调用Pay->Lists->__construct接口结束=====');
	}
	
	public function showView() {
		$this->load->view('module/Pay/lists.htm');
	}
	
	public function getListData() {
		log_message('debug', '=====开始调用Pay->Lists->getListData接口=====');
		$this->verifyPrivilege();
		
		try{
			$gameAreaId = $this->param->getParam('gameAreaId', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 201, 'invalidErrorCode' => 1));
			//$account = $this->param->getParam('account', array('method' => 'string', 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			//$roleName = $this->param->getParam('roleName', array('method' => 'string', 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$startDateTime = $this->param->getParam('startDateTime', array('method' => 'string', 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$endDateTime = $this->param->getParam('endDateTime', array('method' => 'string', 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$page = $this->param->getParam('page', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$rows = $this->param->getParam('rows', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			
			//if( !$account && !$roleName ) {
			//	throw new Exception('', 202);
			//}
	
			$this->initGameAreaInfo($gameAreaId);
			
			$sql = "
				select
					<selectColumns>
				from
					`t_data_game_pay` a
				left join
					`t_data_game_account` b
				on
					a.`userId` = b.`userId`
				where
				 	b.`gameAreaId` = '{$gameAreaId}'
				and
					a.`orderId` not like 'SEND_VIP_%'
			";
			
			if($startDateTime) {
				$sql .= " and a.`payDateTime` >= '{$startDateTime}'";
			}
			
			if($endDateTime) {
				$sql .= " and a.`payDateTime` <= '{$endDateTime}'";
			}
			$sql .= " group by a.`userId` ";
			
			//$getTotalSql = str_replace('<selectColumns>', "count(*)", $sql);
			//$this->returnData['data']['total'] = $this->gmDatabase->getColumn($getTotalSql);
			
			$getDataSql = str_replace('<selectColumns>', "b.`roleName`, sum(a.`money`) as `money`", $sql);
			$getDataSql .= " order by `money` desc ";

//			if($page && $rows) {
//				$startRow = ($page - 1) * $rows;
//				$getDataSql .= " limit {$startRow}, {$rows}";
//			}

			
			$this->returnData['data']['rows'] = $this->gmDatabase->getArray($getDataSql);
		}
		
		catch(MY_Param_Exception $e) {
			$this->setErrorCode($e->getCode());
		}
		
		catch(MY_Mysql_Exception $e) {
			$this->setErrorCode(1);
		}
		
		catch(Exception $e) {
			$this->setErrorCode($e->getCode());
		}
		
		$this->returnJson();
		log_message('debug', '=====调用Pay->Lists->getListData接口结束=====');
	}
}